package com.taoyibao.hongcanting.ui.mine.delegate;

import android.text.TextUtils;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.ToastUtils;
import com.taoyibao.hongcanting.widget.AmountEditText;

/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 15:44
 */
public class RechargeDelegate extends BackToolbarDelegate implements View.OnClickListener {
    private TextView mTvAccount;
    private RadioGroup mRadioGroup;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_recharge;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("充值");
        mTvAccount = get(R.id.tv_recharge_account);
        mTvAccount.setText(CodeUtils.formatHintPhone(SpUtils.getUserPhone()));
        mRadioGroup = get(R.id.rg_recharge_way);
        get(R.id.layout_recharge_wechart).setOnClickListener(this);
        get(R.id.layout_recharge_aliPay).setOnClickListener(this);
    }

    /**
     * 获取充值金额
     *
     * @return
     */
    public double getAmount() {
        String trim = ((AmountEditText) get(R.id.et_recharge_amount)).getText().toString().trim();
        if (TextUtils.isEmpty(trim)) {
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintInputRechargeAmount));
            return 0;
        }
        try {
            double amount = Double.parseDouble(trim);
            return amount;
        } catch (Exception e) {
            e.printStackTrace();
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintInputRechargeAmount));
            return 0;
        }
    }

    /**
     * 获取支付方式
     *
     * @return
     */
    public int getPayWay() {
        switch (mRadioGroup.getCheckedRadioButtonId()) {
            case R.id.rb_recharge_weChart:
                return CodeConstant.PAY_WECHART;
            case R.id.rb_recharge_aliPay:
                return CodeConstant.PAY_ALIPAY;
        }
        return 0;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_recharge_wechart:
                ((RadioButton) get(R.id.rb_recharge_weChart)).setChecked(true);
                break;
            case R.id.layout_recharge_aliPay:
                ((RadioButton) get(R.id.rb_recharge_aliPay)).setChecked(true);
                break;
        }
    }
}
